#ifndef STONE_H
#define STONE_H

#include <QString>

class Stone
{
public:
    Stone();
    enum TYPE{KING, CHE, MA, PAO, XIANG, SHI, BING};
    int row, col, id;
    bool isAlive, red;
    TYPE type;

    QString getText() {
        switch(this->type) {
        case KING:
            if (red)
                return "帅";
            else
                return "将";
        case CHE:
            return "车";
        case MA:
            return "马";
        case PAO:
            return "炮";
        case XIANG:
            if (red)
                return "相";
            else if (!red)
                return "象";
        case SHI:
            if (red)
                return "仕";
            else
                return "士";
        case BING:
            if (red)
                return "兵";
            else if (!red)
                return "卒";
        }
    }

    void init(int id) {
        struct {
            int row, col;
            Stone::TYPE type;
        } pos[16] = {
        {1, 1, Stone::CHE},
        {1, 2, Stone::MA},
        {1, 3, Stone::XIANG},
        {1, 4, Stone::SHI},
        {1, 5, Stone::KING},
        {1, 6, Stone::SHI},
        {1, 7, Stone::XIANG},
        {1, 8, Stone::MA},
        {1, 9, Stone::CHE},
        {3, 2, Stone::PAO},
        {3, 8, Stone::PAO},
        {4, 1, Stone::BING},
        {4, 3, Stone::BING},
        {4, 5, Stone::BING},
        {4, 7, Stone::BING},
        {4, 9, Stone::BING},
        };

        this->id = id;
        isAlive = true;
        red = id < 16;

        if(id < 16) {
            this->row = pos[id].row;
            this->col = pos[id].col;
            this->type = pos[id].type;
        } else {
            this->row = 11-pos[id-16].row; //行对称：1+10=2+8……
            this->col = 10-pos[id-16].col; //列对称：1+9=2+7……
            this->type = pos[id-16].type;
        }

    }

//    void rotate() {
//        this->row = 11 - this->row;
//        this->col = 10 - this->col;
//    }
};

#endif // STONE_H
